package utils

import (
	"crypto/rand"
	"fmt"
	"io"
)

func NewUUID() (string, error) {
	uuid := make([]byte, 16) // // 16 bytes = 128 bits
	n, err := io.ReadFull(rand.Reader, uuid)
	if n != len(uuid) || err != nil {
		return "", err
	}
	// Set the version
	uuid[6] = (uuid[6] & 0x0f) | 0x40 // version 4

	// Set the variant
	uuid[8] = (uuid[8] & 0x3f) | 0x80 // variant 10

	// Format the UUID string
	return fmt.Sprintf("%x-%x-%x-%x-%x", uuid[0:4], uuid[4:6], uuid[6:8], uuid[8:10], uuid[10:]), nil

}
